using System;
using System.Collections.Generic;

public static class Messenger<T>
{
	public static void AddListener(string eventType, Callback<T> handler)
	{
		MessengerInternal.OnListenerAdding(eventType, handler);
		Messenger<T>.eventTable[eventType] = (Callback<T>)Delegate.Combine((Callback<T>)Messenger<T>.eventTable[eventType], handler);
	}

	public static void RemoveListener(string eventType, Callback<T> handler)
	{
		MessengerInternal.OnListenerRemoving(eventType, handler);
		Messenger<T>.eventTable[eventType] = (Callback<T>)Delegate.Remove((Callback<T>)Messenger<T>.eventTable[eventType], handler);
		MessengerInternal.OnListenerRemoved(eventType);
	}

	public static void Broadcast(string eventType, T arg1)
	{
		Messenger<T>.Broadcast(eventType, arg1, MessengerInternal.DEFAULT_MODE);
	}

	public static void Broadcast(string eventType, T arg1, MessengerMode mode)
	{
		MessengerInternal.OnBroadcasting(eventType, mode);
		Delegate @delegate;
		if (Messenger<T>.eventTable.TryGetValue(eventType, out @delegate))
		{
			Callback<T> callback = @delegate as Callback<T>;
			if (callback == null)
			{
				throw MessengerInternal.CreateBroadcastSignatureException(eventType);
			}
			callback(arg1);
		}
	}

	private static Dictionary<string, Delegate> eventTable = MessengerInternal.eventTable;
}
